class BaseWidget {
  constructor(id, config = {}) {
    this.id = id;
    this.config = config;
    this.data = {};
    this.createdAt = new Date();
    this.updatedAt = new Date();
    this.dbManager = null;
  }

  setDatabaseManager(dbManager) {
    this.dbManager = dbManager;
  }

  getDatabaseManager() {
    return this.dbManager;
  }

  getName() {
    return this.constructor.name;
  }

  getVersion() {
    return this.constructor.version || '1.0.0';
  }

  getDescription() {
    return this.constructor.description || 'No description';
  }

  getConfigSchema() {
    return this.constructor.configSchema || {};
  }

  updateConfig(newConfig) {
    this.config = { ...this.config, ...newConfig };
    this.updatedAt = new Date();
  }

  getData() {
    return {
      ...this.data,
      id: this.id,
      name: this.getName(),
      version: this.getVersion(),
      config: this.config,
      createdAt: this.createdAt,
      updatedAt: this.updatedAt
    };
  }

  updateData(newData) {
    this.data = { ...this.data, ...newData };
    this.updatedAt = new Date();
  }

  destroy() {
    this.data = {};
    this.config = {};
  }

  static get version() {
    return '1.0.0';
  }

  static get description() {
    return 'Base widget class';
  }

  static get configSchema() {
    return {};
  }
}

module.exports = BaseWidget;